<form method="post" name="show_units_form" action="">
<table class="Centered List" border="0">
  <tr class="HeaderTr">
    <td class="LeftAlign" colspan="8"><b>Units</b></td>
  </tr>
  <tr class="HeaderTr">
    <th width="15px"><input type="checkbox" name="" onclick="select_all(this);" /></th>
    <th class="LeftAlign" width="30%">Unit Name</th>
    <th>Category</th>
    <th width="7%">Bedrooms</th>
    <th width="20%">Unit Manager</th>
    <th width="7%">Published</th>
    <th width="5%">Unit ID</th>
    <th width="8%">Order</th>
  </tr>
  <?php if(!empty($units)){?>
	  <?php foreach($units as $key=>$unit){?>
	  <tr class="<?php echo($key%2 == 0 ? 'row0' : 'row1'); ?>">
	    <td><input type="checkbox" name="units[ids][]" value="<?php echo $unit->id;?>" /></td>
	    <td class="LeftAlign"><a href="?option=<?php echo COMPONENT_NAME;?>&page=units&action=edit&uid=<?php echo $unit->id;?>"><?php echo $unit->name;?></a></td>
	    <td><?php echo $unit->categories->name;?></td>
	    <td><?php echo $unit->bedrooms;?></td>
	    <td>
	    	<?php
				$manager_name = $unit->customers->firstname." ".$unit->customers->surname;
				echo $manager_name;
	    	?>
	    </td>
	    <td>
	    	<a class="Published" style="display: <?php echo($unit->published == 1 ? 'inline':'none')?>" href="javascript:void(0);" onclick="alter_published_state(0, '<?php echo $unit->id;?>', this)"><img alt="published" src="<?php echo COMPONENT_PATH."images/published.png";?>" /></a>
	    	<a class="UnPublished" style="display: <?php echo($unit->published != 1 ? 'inline':'none')?>" href="javascript:void(0);" onclick="alter_published_state(1, '<?php echo $unit->id;?>', this)"><img alt="not published" src="<?php echo COMPONENT_PATH."images/cross.png";?>" /></a>
	    </td>
	    <td><?php echo $unit->id;?></td>
	    <td><?php ?></td>
	  </tr>
	  <?php }?>
  <?php }else{?>
  		<tr><td colspan="8" class="Info LeftAlign"><b>No units have been added yet.</b></td></tr>
  <?php }?>
  <tr class="HeaderTr">
	<td colspan="8" class="LeftAlign">
		<?php if( $paginate['pg_no'] == 1 ){?>
			&lt;&lt;Start&nbsp;&nbsp;&lt;Previous&nbsp;
		<?php }else{?>
			<a href="?option=<?php echo COMPONENT_NAME;?>&page=bookings&pg_no=1&limit=<?php echo $paginate['limit'];?>">&lt;&lt;Start</a>&nbsp;&nbsp;<a href="?option=<?php echo COMPONENT_NAME;?>&page=bookings&pg_no=<?php echo $paginate['prev'];?>&limit=<?php echo $paginate['limit'];?>">&lt;Previous</a>
		<?php }?>
		<?php for($i = 1; $i <= $paginate['max_page']; $i++){?>
			<?php if( $i == $paginate['pg_no'] ){?>
				<?php echo $i;?>
			<?php }else{?>
				&nbsp;&nbsp;<a href="?option=<?php echo COMPONENT_NAME;?>&page=bookings&pg_no=<?php echo $i;?>&limit=<?php echo $paginate['limit'];?>"><?php echo $i;?></a>&nbsp;&nbsp;
			<?php }?>
		<?php }?>
		<?php if($paginate['pg_no'] == $paginate['max_page']){?>
			&nbsp;Next&gt;&nbsp;&nbsp;End&gt;&gt;
		<?php }else{?>
			<a href="?option=<?php echo COMPONENT_NAME;?>&page=bookings&pg_no=<?php echo $paginate['next'];?>&limit=<?php echo $paginate['limit'];?>">Next&gt;</a>&nbsp;&nbsp;<a href="?option=<?php echo COMPONENT_NAME;?>&page=bookings&pg_no=<?php echo $paginate['max_page'];?>&limit=<?php echo $paginate['limit'];?>">End&gt;&gt;</a>
		<?php }?>
	</td>
  </tr>
  <tr>
  	<td align="center" colspan="13" class="RowsDisplayTd">
  		<select onchange="document.show_units_form.submit()" size="1" name="limit">
			<option value="5" <?php echo ($limit == 5 ? 'selected = "selected"' : ''); ?>>5</option>
			<option value="10" <?php echo ($limit == 10 ? 'selected = "selected"' : ''); ?>>10</option>
			<option value="15" <?php echo ($limit == 15 ? 'selected = "selected"' : ''); ?>>15</option>
			<option value="20" <?php echo ($limit == 20 ? 'selected = "selected"' : ''); ?>>20</option>
			<option value="25" <?php echo ($limit == 25 ? 'selected = "selected"' : ''); ?>>25</option>
			<option value="30" <?php echo ($limit == 30 ? 'selected = "selected"' : ( empty($limit) ? 'selected = "selected"' : '' )); ?>>30</option>
			<option value="50" <?php echo ($limit == 50 ? 'selected = "selected"' : ''); ?>>50</option>
		</select>
		rows
  	</td>
  </tr>
</table>
<input type="hidden" name="form" value="filter" />
<!--<input type="submit" value="submit">-->
</form>
<?php $KToolBar->addLink('<a href="?option='.COMPONENT_NAME.'&page=units&action=new"><img border="0" alt="New Unit" src="images/new_f2.png"/><br />New</a>');?>
<?php $KToolBar->addLink('<a href="#" onclick="delete_selected(\'show_units_form\')"><img border="0" alt="Delete Units" src="images/delete_f2.png"/><br />Delete</a>');?>
<?php $KToolBar->addLink('<a href="?option='.COMPONENT_NAME.'"><img border="0" alt="Cancel" src="images/cancel_f2.png"/><br />Cancel</a>');?>
<script type="text/javascript">
function alter_published_state(state, id, ele){
	if(ele.className == "Published") var index = $(".Published").index(ele);
	else if(ele.className == "UnPublished") var index = $(".UnPublished").index(ele);
	$.post("<?php echo COMPONENT_PATH."functions/change_published.php";?>", { published: state, id: id },function(data){
		if(data == 1) {
			$(".UnPublished:eq("+index+")").css("display", "none");
			$(".Published:eq("+index+")").css("display", "inline");
		}
		else if(data == 0) {
			$(".Published:eq("+index+")").css("display", "none");
			$(".UnPublished:eq("+index+")").css("display", "inline");
		}
		else alert("Some error occured. Make sure you are connected to the network.");
	});
}
</script>